<html lang="en" xml:lang="en"><head>
<META http-equiv="Content-Type" content="text/html">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><META name="description" content="Describes how widgets communicate with each other"><meta name="content-language" content="en"><link href="rsrc/htmlhelp.css" rel="stylesheet" type="text/css"><title>Web AppBuilder for ArcGIS | Help - 
Communication between widgets
</title>
                <script type="text/javascript" language="JavaScript">
                    var pathL  = self.location.pathname.split ("/");
                    var fname = pathL[pathL.length-1];
                    var i = fname.lastIndexOf (".htm");
                    if (i>=0) {
                    fname = fname.substring (0, i)
                    } else {
                    //??
                    }
                    if (self.location.hash) {
				    		      fname = fname + self.location.hash;
						        }
                    self.location.replace ("../index.html#//" + fname);
                </script>
                </head><!--Publication GUID: [GUID-E7D1C130-8F87-4109-8D61-E73A46083F52]--><!--Topic GUID: [GUID-2FBDF680-A4BC-4273-BB81-13A9CCDA06C9]--><body><div id="content"><div class="header"><h1>
Communication between widgets
</h1><div id="breadcrumb"></div></div>
<p id="GUID-EFAB4FDD-3592-4DB6-A474-E2A4467F9064">The BaseWidget class supports reading or sending data between widgets. In the constructor of the BaseWidget class, the publishData, dataFetched, and noData events are subscribed. The  BaseWidget class also provides the publishData and fetchData methods.</p><p id="GUID-EB1732B5-12EB-4ED4-A9FD-6B3CFC5673BB">If you want the widget to publish data, call the publishData method. If you want the widget to receive data from another widget, call the fetchData method, and write code to override the onReceiveData and onNoData methods to read data.</p>

<p id="GUID-8E159013-F43F-424D-BC74-C967C379AF3C">  All published data is stored in a data store called DataManager. As a result, the widget can receive    published data before it is loaded. For example, widget B wants to read data from widget A. Before widget B is loaded, the data published by widget A  is stored in DataManager. When widget B is loaded, it calls the fetchData method to fetch the data from DataManager. After widget B is loaded, it receives all of the published data from widget A.  In some case, you may want to open another widget by <span class="usertext">this.openWidgetById</span>   method before sending the message to it. The following diagram illustrates this workflow:<div class="image" purpose="image"><table><tr><td><img class="break" src="03w3/GUID-CD408C20-7327-431A-A42B-1482DAB022B3-web.png" purpose="img" alt="Communication between widgets" title="Communication between widgets"></td></tr></table></div></p><p id="GUID-D8FCD823-1A78-4695-8747-589371AB6DCD">See WidgtCommunication sample in <span class="usertext">\client\stemapp\widgets\samplewidgets</span> directory of Web AppBuilder installation.</p><div class="notes" id="GUID-E585E0FF-5C79-4711-9873-41BC42EB99B6"><div class="note"><img class="note_img" src="rsrc/note.png" alt="Note" title="Note"><span>Note:</span></div><div class="tipbody"><p id="GUID-1B7C7772-622F-4BBD-B5B6-848E9AE1EB2C"> Since version 2.1 and up, you can  pass feature set between widgets. See <a class="xref" rel="03w3/03w30000009v000000.htm" href="03w3/03w30000009v000000.htm">Create a feature action in your widget</a> for details.</p></div></div><p id="GUID-50912DA0-1E77-40B9-B5C4-01667FFC1479">The method details are described in the following table:</p><p id="GUID-D0D8A787-E26A-4EAE-AC16-D6856241FD23"><div class="block_table" id="TABLE_D39131F1CFDB4A9294B37B7997F9D058" purpose="block_table"><span class="table_title"></span><table class="table"><colgroup width="*"></colgroup><colgroup width="*"></colgroup><tr purpose="thead"><th class="th" purpose="th" rowspan="1" colspan="1"><p id="GUID-18BDEED9-621E-4D43-93F9-DCB783D7E5FC">Name</p></th><th class="th" purpose="th" rowspan="1" colspan="1"><p id="GUID-A27F0252-BCFD-434A-A5FE-CCFEBC7DD278">Parameter</p></th></tr><tbody><tr><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-0DE9FB71-A0DC-4DA6-AD88-B9285C55DB32"><span class="usertext">publishData</span></p></td><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-507050C4-3AD7-4659-AA6F-610D3299E083">Publishes the data.<ul purpose="ul" id="UL_998A8AC700EB42C4AA24DE8F578D2FF8"><li purpose="li" id="LI_EC9E51916261464D88FCDAA9962632FD">data—The data published by the widget.</li><li purpose="li" id="LI_8640726DEEC84FFAB235FB97E3F86107"> keepHistory—If true, all published data is stored in DataManager, which may cause memory problems. If false, only the latest data is stored in DataManager. The default value is false.</li></ul></p></td></tr><tr><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-AFC7E081-48F2-4E06-BCE3-A326C2536BB4"><span class="usertext">fetchData</span></p></td><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-F4464549-3B1B-4CD9-A36A-A6F48B3D2DD4">Fetches the data. <ul purpose="ul" id="UL_2F24A734D15040788703D7AFF086DA35"><li purpose="li" id="LI_F4E4203E8F6B4098B02F08569DB79679">widgetId-The widget’s ID from which you want to fetch the data. If omitted, all data is fetched. You can get the widget ID from app config.json.</li></ul></p></td></tr><tr><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-1B21291E-CD9D-4209-8117-62C63DC10F47"><span class="usertext">fetchDataByName</span></p></td><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-E60CA3EE-155A-4F9F-9E97-745CB5BF1EE7">Fetches the data </p><ul purpose="ul" id="UL_432D66CD5C8C4801BEF01F58007749C3"><li purpose="li" id="LI_CC5218AEEC3F4D47B1FE6CD9C6EAB007">widgetName—The widget’s name from which you want to fetch data. Although  the widget ID may change from one app to another,  the widget name is unique. You can use this method to fetch the data. If the same widget is configured more than once in an  app, however, these widgets cannot be identified by the widget name.</li></ul></td></tr><tr><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-A41EE7D5-B998-4729-8AB9-884CF438328F"><span class="usertext"> onReceiveData</span></p></td><td purpose="entry" rowspan="1" colspan="1"><p id="GUID-F7044F83-6D1A-4B6E-9081-B28F89DC5C25">Invoked when data is available.</p><ul purpose="ul" id="UL_4B926749267443DD8378185CC8018D08"><li purpose="li" id="LI_A86ADA52B25B471196265803AAEA8896">widgetName—The name of the widget  that publishes data.</li><li purpose="li" id="LI_FE4A9B17DF954DC49D6FB872BCB362DC">widgetId—The ID  of the widget that publishes data.</li><li purpose="li" id="LI_8A9347AC7F66475B8525D81079FD25A4">data—The data.</li><li purpose="li" id="LI_7121B309147349DF9736EEE3D56E9508">historyData—The history data that widget has published. It may have three values: undefined, true and object.<ul purpose="ul" id="UL_90FA2C9E79384C02AFFEB7CD33F392E0"><li purpose="li" id="LI_5AFB81A994F3428CABACD2CFFB35C7D4">undefined--Data published without history.</li><li purpose="li" id="LI_CECD8021C864488AB75CAB0E24A223F1">true--Data published with history. If the widget wants to fetch the history data, call fetchData method.</li><li purpose="li" id="LI_B42AA7F8455E4B628BE09096679B5CF8">objec--The history data.</li></ul></li></ul></td></tr></tbody></table><span class="table_desc"></span></div></p><div class="footer"> Copyright © 1995-2016 Esri. All rights reserved. </div></div></body></html>